<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>

  <div id="app">
    <button @click="show=!show">switch</button>
    <aki v-if="show"></aki>
  </div>

  <script>
  const { createApp, ref, onMounted, onUnmounted }  = Vue;

  const Aki = {
    template: `
    <h1>AkiyamaMio</h1>
    `,
    setup(){
        let int = null;
        onMounted(()=>{
            console.log('已经挂载');

            int = setInterval(()=>{
                console.log('挂载中');
            },1000)
        });

        onUnmounted(()=>{
            console.log('已经卸载');
            clearInterval(int);
        })
    }

  }

  const app = createApp({
    components:{
        Aki
    },
    setup(){
        const show = ref(false);

        return { show }
    }
  });


  app.mount('#app');

  </script>

</body>
</html>